<!DOCTYPE html>
<html>

<head>
  <script src="../node_modules/angular/angular.js"></script>
</head>

<body ng-app="demo">
  <div ng-controller="DemoController">
    <p>{{ currentTime }}</p>
  </div>
  <script>
    angular
      .module('demo', [])
      .controller('DemoController', ['$scope', '$timeout', function ($scope, $timeout) {
        $scope.currentTime = new Date().toLocaleString()
        function update() {
          setTimeout(() => {
            $scope.currentTime = new Date().toLocaleString()
            // $scope.$apply() // 手动触发一次脏检查
            console.log($scope.currentTime)
            update()
          }, 1000)
        }
        update()
      }]);
  </script>


  <!-- <div ng-controller="TimeController">
    <p>{{ currentTime }}</p>
  </div>
  <script>
    angular
      .module('demo')
      .controller('TimeController', ['$scope', '$timeout', function ($scope, $timeout) {
        $scope.currentTime = new Date().toLocaleString()
        function update() {
          $timeout(() => {
            $scope.currentTime = new Date().toLocaleString()
            console.log($scope.currentTime)
            update()
          }, 1000)
        }
        update()
      }]);
  </script> -->
</body>

</html>